package com.jiguang.gaodejicheng.activity;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.model.LatLng;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.enums.NaviType;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.NaviLatLng;
import com.jiguang.gaodejicheng.MainActivity;
import com.jiguang.gaodejicheng.R;

import java.text.SimpleDateFormat;
import java.util.Date;

import static com.amap.api.maps.AMapUtils.calculateLineDistance;


public class EmulatorActivity extends BaseActivity {
    private boolean flag = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_basic_navi);
        mAMapNaviView = (AMapNaviView) findViewById(R.id.navi_view);
        mAMapNaviView.onCreate(savedInstanceState);
        mAMapNaviView.setAMapNaviViewListener(this);
    }

    @Override
    public void onInitNaviSuccess() {
        super.onInitNaviSuccess();
        /**
         * 方法: int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute); 参数:
         *
         * @congestion 躲避拥堵
         * @avoidhightspeed 不走高速
         * @cost 避免收费
         * @hightspeed 高速优先
         * @multipleroute 多路径
         *
         *  说明: 以上参数都是boolean类型，其中multipleroute参数表示是否多条路线，如果为true则此策略会算出多条路线。
         *  注意: 不走高速与高速优先不能同时为true 高速优先与避免收费不能同时为true
         */
        int strategy = 0;
        try {
            //再次强调，最后一个参数为true时代表多路径，否则代表单路径
            strategy = mAMapNavi.strategyConvert(true, false, false, false, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);

    }

    @Override
    public void onCalculateRouteSuccess(int[] ids) {
        super.onCalculateRouteSuccess(ids);
        mAMapNavi.startNavi(NaviType.EMULATOR);
    }

    @Override
    public void onArriveDestination() {
        //到达目的地

        Toast.makeText(EmulatorActivity.this, "我已经到目的地了", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onStartNavi(int type) {
        //开始导航回调

        Toast.makeText(EmulatorActivity.this, "开始导航回调", Toast.LENGTH_LONG).show();
    }
    

    @Override
    public void onLocationChange(AMapNaviLocation location) {
        //当前位置回调
        NaviLatLng coord = location.getCoord();
        double latitude = coord.getLatitude();//纬度
        // Toast.makeText(EmulatorActivity.this, "当前纬度" + latitude, Toast.LENGTH_LONG).show();
        double longitude = coord.getLongitude();//经度
        // Toast.makeText(EmulatorActivity.this, "当前经度" + longitude, Toast.LENGTH_LONG).show();
        LatLng latlngA = new LatLng(latitude, longitude);
        LatLng latlngB = new LatLng(39.826000, 116.350000);
        Float distance = AMapUtils.calculateLineDistance(latlngA, latlngB);
        if (flag) {
            if (distance < 100) {
                Toast.makeText(EmulatorActivity.this, "我已经到目的地的附近了", Toast.LENGTH_LONG).show();
                flag = false;
            }
        }
    }
}
